﻿using Avalonia.Controls;
using Avalonia.Interactivity;
using LuckyFish.ToDo.Data.Model;
using LuckyFish.ToDo.ViewModels;

namespace LuckyFish.ToDo.AddViews;

public partial class AddGroupView : UserControl
{
    public AddGroupView()
    {
        InitializeComponent();
        GroupBox = this.FindControl<TextBox>("GroupBox");
    }

    private void OkClick(object? sender, RoutedEventArgs e)
    {
        if(Parent?.DataContext is not MainWindowViewModel model || string.IsNullOrEmpty(GroupBox.Text))return;
        model.Add(new ToDoGroupModel
        {
            GroupName = GroupBox.Text
        });
        model.ToWelcomeView();
    }

    private void Cancel(object? sender, RoutedEventArgs e)
    {
        if(Parent?.DataContext is not MainWindowViewModel model)return;
        model.ToWelcomeView();
    }
}